home *** CD-ROM | disk | FTP | other *** search
/ Delphi Informant Complete 1995 - 2000 / Delphi Informant Complete 1995 to 2000.iso / Delphi Informant Magazine Complete Works SOURCE CODE 1998.rar / 1998 / Feb / di9802dm / ActiveForm / AFEmployeeImp.pas < prev    next >
Pascal/Delphi Source File  |  1997-08-12  |  8KB  |  337 lines

  1. unit AFEmployeeImp;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ActiveX, AxCtrls, EmpForm_TLB, StdCtrls, Db, DBTables, ExtCtrls, DBCtrls,
  8.   Grids, DBGrids;
  9.  
  10. type
  11.   TAFEmployee = class(TActiveForm, IAFEmployee)
  12.     DBGrid1: TDBGrid;
  13.     DBNavigator1: TDBNavigator;
  14.     dsEmployee: TDataSource;
  15.     tblEmployee: TTable;
  16.     lblSearch: TLabel;
  17.     edSearch: TEdit;
  18.     btnSearch: TButton;
  19.     procedure btnSearchClick(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.     FEvents: IAFEmployeeEvents;
  23.     procedure ActivateEvent(Sender: TObject);
  24.     procedure ClickEvent(Sender: TObject);
  25.     procedure CreateEvent(Sender: TObject);
  26.     procedure DblClickEvent(Sender: TObject);
  27.     procedure DeactivateEvent(Sender: TObject);
  28.     procedure DestroyEvent(Sender: TObject);
  29.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  30.     procedure PaintEvent(Sender: TObject);
  31.   protected
  32.     { Protected declarations }
  33.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  34.     procedure Initialize; override;
  35.     function Get_Active: WordBool; safecall;
  36.     function Get_AutoScroll: WordBool; safecall;
  37.     function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
  38.     function Get_Caption: WideString; safecall;
  39.     function Get_Color: TColor; safecall;
  40.     function Get_Cursor: Smallint; safecall;
  41.     function Get_DropTarget: WordBool; safecall;
  42.     function Get_Enabled: WordBool; safecall;
  43.     function Get_Font: Font; safecall;
  44.     function Get_HelpFile: WideString; safecall;
  45.     function Get_KeyPreview: WordBool; safecall;
  46.     function Get_PixelsPerInch: Integer; safecall;
  47.     function Get_PrintScale: TxPrintScale; safecall;
  48.     function Get_Scaled: WordBool; safecall;
  49.     function Get_Visible: WordBool; safecall;
  50.     function Get_WindowState: TxWindowState; safecall;
  51.     procedure Set_AutoScroll(Value: WordBool); safecall;
  52.     procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
  53.     procedure Set_Caption(const Value: WideString); safecall;
  54.     procedure Set_Color(Value: TColor); safecall;
  55.     procedure Set_Cursor(Value: Smallint); safecall;
  56.     procedure Set_DropTarget(Value: WordBool); safecall;
  57.     procedure Set_Enabled(Value: WordBool); safecall;
  58.     procedure Set_Font(const Value: Font); safecall;
  59.     procedure Set_HelpFile(const Value: WideString); safecall;
  60.     procedure Set_KeyPreview(Value: WordBool); safecall;
  61.     procedure Set_PixelsPerInch(Value: Integer); safecall;
  62.     procedure Set_PrintScale(Value: TxPrintScale); safecall;
  63.     procedure Set_Scaled(Value: WordBool); safecall;
  64.     procedure Set_Visible(Value: WordBool); safecall;
  65.     procedure Set_WindowState(Value: TxWindowState); safecall;
  66.     function Get_Search: WideString; safecall;
  67.     procedure Set_Search(const Value: WideString); safecall;
  68.     function FindEmployee(EmpNo: Integer): WordBool; safecall;
  69.     procedure ShowSearchControls(Value : WordBool); safecall;
  70.   public
  71.     { Public declarations }
  72.   end;
  73.  
  74. implementation
  75.  
  76. uses ComServ;
  77.  
  78. {$R *.DFM}
  79.  
  80. { TAFEmployee }
  81.  
  82. procedure TAFEmployee.EventSinkChanged(const EventSink: IUnknown);
  83. begin
  84.   FEvents := EventSink as IAFEmployeeEvents;
  85. end;
  86.  
  87. procedure TAFEmployee.Initialize;
  88. begin
  89.   OnActivate := ActivateEvent;
  90.   OnClick := ClickEvent;
  91.   OnCreate := CreateEvent;
  92.   OnDblClick := DblClickEvent;
  93.   OnDeactivate := DeactivateEvent;
  94.   OnDestroy := DestroyEvent;
  95.   OnKeyPress := KeyPressEvent;
  96.   OnPaint := PaintEvent;
  97. end;
  98.  
  99. function TAFEmployee.Get_Active: WordBool;
  100. begin
  101.   Result := Active;
  102. end;
  103.  
  104. function TAFEmployee.Get_AutoScroll: WordBool;
  105. begin
  106.   Result := AutoScroll;
  107. end;
  108.  
  109. function TAFEmployee.Get_AxBorderStyle: TxActiveFormBorderStyle;
  110. begin
  111.   Result := Ord(AxBorderStyle);
  112. end;
  113.  
  114. function TAFEmployee.Get_Caption: WideString;
  115. begin
  116.   Result := WideString(Caption);
  117. end;
  118.  
  119. function TAFEmployee.Get_Color: TColor;
  120. begin
  121.   Result := Color;
  122. end;
  123.  
  124. function TAFEmployee.Get_Cursor: Smallint;
  125. begin
  126.   Result := Smallint(Cursor);
  127. end;
  128.  
  129. function TAFEmployee.Get_DropTarget: WordBool;
  130. begin
  131.   Result := DropTarget;
  132. end;
  133.  
  134. function TAFEmployee.Get_Enabled: WordBool;
  135. begin
  136.   Result := Enabled;
  137. end;
  138.  
  139. function TAFEmployee.Get_Font: Font;
  140. begin
  141.   GetOleFont(Font, Result);
  142. end;
  143.  
  144. function TAFEmployee.Get_HelpFile: WideString;
  145. begin
  146.   Result := WideString(HelpFile);
  147. end;
  148.  
  149. function TAFEmployee.Get_KeyPreview: WordBool;
  150. begin
  151.   Result := KeyPreview;
  152. end;
  153.  
  154. function TAFEmployee.Get_PixelsPerInch: Integer;
  155. begin
  156.   Result := PixelsPerInch;
  157. end;
  158.  
  159. function TAFEmployee.Get_PrintScale: TxPrintScale;
  160. begin
  161.   Result := Ord(PrintScale);
  162. end;
  163.  
  164. function TAFEmployee.Get_Scaled: WordBool;
  165. begin
  166.   Result := Scaled;
  167. end;
  168.  
  169. function TAFEmployee.Get_Visible: WordBool;
  170. begin
  171.   Result := Visible;
  172. end;
  173.  
  174. function TAFEmployee.Get_WindowState: TxWindowState;
  175. begin
  176.   Result := Ord(WindowState);
  177. end;
  178.  
  179. procedure TAFEmployee.Set_AutoScroll(Value: WordBool);
  180. begin
  181.   AutoScroll := Value;
  182. end;
  183.  
  184. procedure TAFEmployee.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
  185. begin
  186.   AxBorderStyle := TActiveFormBorderStyle(Value);
  187. end;
  188.  
  189. procedure TAFEmployee.Set_Caption(const Value: WideString);
  190. begin
  191.   Caption := TCaption(Value);
  192. end;
  193.  
  194. procedure TAFEmployee.Set_Color(Value: TColor);
  195. begin
  196.   Color := Value;
  197. end;
  198.  
  199. procedure TAFEmployee.Set_Cursor(Value: Smallint);
  200. begin
  201.   Cursor := TCursor(Value);
  202. end;
  203.  
  204. procedure TAFEmployee.Set_DropTarget(Value: WordBool);
  205. begin
  206.   DropTarget := Value;
  207. end;
  208.  
  209. procedure TAFEmployee.Set_Enabled(Value: WordBool);
  210. begin
  211.   Enabled := Value;
  212. end;
  213.  
  214. procedure TAFEmployee.Set_Font(const Value: Font);
  215. begin
  216.   SetOleFont(Font, Value);
  217. end;
  218.  
  219. procedure TAFEmployee.Set_HelpFile(const Value: WideString);
  220. begin
  221.   HelpFile := String(Value);
  222. end;
  223.  
  224. procedure TAFEmployee.Set_KeyPreview(Value: WordBool);
  225. begin
  226.   KeyPreview := Value;
  227. end;
  228.  
  229. procedure TAFEmployee.Set_PixelsPerInch(Value: Integer);
  230. begin
  231.   PixelsPerInch := Value;
  232. end;
  233.  
  234. procedure TAFEmployee.Set_PrintScale(Value: TxPrintScale);
  235. begin
  236.   PrintScale := TPrintScale(Value);
  237. end;
  238.  
  239. procedure TAFEmployee.Set_Scaled(Value: WordBool);
  240. begin
  241.   Scaled := Value;
  242. end;
  243.  
  244. procedure TAFEmployee.Set_Visible(Value: WordBool);
  245. begin
  246.   Visible := Value;
  247. end;
  248.  
  249. procedure TAFEmployee.Set_WindowState(Value: TxWindowState);
  250. begin
  251.   WindowState := TWindowState(Value);
  252. end;
  253.  
  254. procedure TAFEmployee.ActivateEvent(Sender: TObject);
  255. begin
  256.   if FEvents <> nil then FEvents.OnActivate;
  257. end;
  258.  
  259. procedure TAFEmployee.ClickEvent(Sender: TObject);
  260. begin
  261.   if FEvents <> nil then FEvents.OnClick;
  262. end;
  263.  
  264. procedure TAFEmployee.CreateEvent(Sender: TObject);
  265. begin
  266.   if FEvents <> nil then FEvents.OnCreate;
  267. end;
  268.  
  269. procedure TAFEmployee.DblClickEvent(Sender: TObject);
  270. begin
  271.   if FEvents <> nil then FEvents.OnDblClick;
  272. end;
  273.  
  274. procedure TAFEmployee.DeactivateEvent(Sender: TObject);
  275. begin
  276.   if FEvents <> nil then FEvents.OnDeactivate;
  277. end;
  278.  
  279. procedure TAFEmployee.DestroyEvent(Sender: TObject);
  280. begin
  281.   if FEvents <> nil then FEvents.OnDestroy;
  282. end;
  283.  
  284. procedure TAFEmployee.KeyPressEvent(Sender: TObject; var Key: Char);
  285. var
  286.   TempKey: Smallint;
  287. begin
  288.   TempKey := Smallint(Key);
  289.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  290.   Key := Char(TempKey);
  291. end;
  292.  
  293. procedure TAFEmployee.PaintEvent(Sender: TObject);
  294. begin
  295.   if FEvents <> nil then FEvents.OnPaint;
  296. end;
  297.  
  298. procedure TAFEmployee.btnSearchClick(Sender: TObject);
  299. begin
  300.   if edSearch.Text<>'' then begin
  301.     tblEmployee.FindKey([edSearch.Text]);
  302.   end;
  303. end;
  304.  
  305. function TAFEmployee.Get_Search: WideString;
  306. begin
  307.   Result:=edSearch.Text;
  308. end;
  309.  
  310. procedure TAFEmployee.Set_Search(const Value: WideString);
  311. begin
  312.   edSearch.Text:=Value;
  313. end;
  314.  
  315. function TAFEmployee.FindEmployee(EmpNo: Integer): WordBool;
  316. begin
  317.   Result:=tblEmployee.FindKey([edSearch.Text]);
  318. end;
  319.  
  320. procedure TAFEmployee.ShowSearchControls(Value : WordBool);
  321. begin
  322.   lblSearch.Visible:=Value;
  323.   edSearch.Visible:=Value;
  324.   btnSearch.Visible:=Value;
  325. end;
  326.  
  327. initialization
  328.   TActiveFormFact